package com.lightkits.wms.domain.purchasereceive;

import com.lightkits.framework.common.exception.LightKitsBizException;
import com.lightkits.framework.common.model.IResult;
import com.lightkits.framework.common.utility.object.ObjectUtil;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.framework.soa.client.id.IDServiceClient;
import com.lightkits.wms.domain.purchasereceive.service.CreatePurchaseOrderDomain;
import com.lightkits.wms.dto.purchasereceive.ReceivePoRequestType;
import com.lightkits.wms.dto.purchasereceive.ReceivePoResponseType;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ReceivePoExecutor
 *
 * @author jing.wei@hand-china.com
 * Created on 2019/4/26 14:10
 */
@Component
public class ReceivePoExecutor implements ServiceExecutor<ReceivePoRequestType, ReceivePoResponseType> {
    private final IDServiceClient idAdapterService;

    @Autowired
    public ReceivePoExecutor(IDServiceClient idAdapterService, CreatePurchaseOrderDomain purchaseOrderDomain) {
        this.idAdapterService = idAdapterService;
        this.purchaseOrderDomain = purchaseOrderDomain;
    }

    private final CreatePurchaseOrderDomain purchaseOrderDomain;

    @Override
    public ReceivePoResponseType service(ReceivePoRequestType request) {
        ReceivePoResponseType response = new ReceivePoResponseType();
        response.setSuccessful(true);
        try {
            IResult result = purchaseOrderDomain.receivePo(request.getPoParamsDTO());
            if (result.isSuccessful()) {
                return result.fill(response);
            }
            result.fill(response);

        } catch (Exception e) {
            response.setSuccessful(false);
            response.setMessage("Receive Purcharse Order Error");
        }
        return response;
    }
}
